package org.com.behavioralPattern.mementoPattern;

import java.util.LinkedList;

/**
 * @author Jonny
 * @version 1.0
 * @Description:
 * @date 2021/4/27 17:22
 */

/**
 *
 * 备忘录模式优缺点
 *
 *
 */
public class VersionControlSystem {
    LinkedList<Backup> backlist=new LinkedList<Backup>();

    int nextVersion;

    public void AddBack(Backup backup){
        backup.version=++nextVersion;
        backlist.add(backup);
    }

    public Backup getBackup(int version){
        for(Backup b:backlist){
            if(b.version==version){
                return b;
            }
        }
        return null;
    }

    public Backup getlastBackup(){
        return backlist.getLast();
    }
}
